<script>
	import { getContext } from 'svelte';
	import { t } from 'svelte-i18n';
	import { assets } from '$lib/store/app-stores';
	import { playSfx } from '$lib/helpers/audio/audio';
	import EpitomizedIcon from '../../epitomized-path/_icon.svelte';

	export let courseData = {};
	let selected, type, point;
	$: ({ type, weaponType, selected, point } = courseData);
	$: src = type === 'weapon' ? $assets[selected] : $assets[`face/${selected}`];

	const openModal = getContext('handleEpitomizedModal');
	const openDetail = () => {
		playSfx();
		openModal();
	};
</script>

<div class="courseActive">
	<button class="box" on:click={openDetail}>
		<div class="icon" class:active={point > 0}>
			<EpitomizedIcon blank responsive steps="1" {point} />
			<picture class="{type} {weaponType}">
				<img {src} alt="Item Icon" />
			</picture>
		</div>

		<div class="point">
			<div class="frame">
				<span> {$t('epitomizedPath.fatePoint')}:</span>
				<div class="number"><span>{point || 0}</span>/1</div>
				<i class="gi-refresh" />
			</div>
		</div>
	</button>
</div>

<style>
	.courseActive {
		margin-top: auto;
		width: 100%;
		height: calc(0.125 * var(--content-width));
		margin-bottom: 2.75%;
	}
	.box {
		height: inherit;
		position: relative;
	}
	.icon {
		height: 100%;
		aspect-ratio: 1/1;
		position: relative;
		z-index: +1;
	}
	.icon:not(.active)::after {
		content: '';
		width: 100%;
		height: 100%;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%) scale(1.05);
		border-radius: 100%;
		border: calc(0.002 * var(--content-width)) solid #edd8ab;
	}
	picture {
		height: 60%;
		aspect-ratio: 1/1;
		display: block;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		border-radius: 100%;
		overflow: hidden;
	}
	img {
		width: 100%;
	}
	.weapon:not(.catalyst) img {
		transform: translate(-5%, -10%) rotate(13deg);
	}

	/* Point */
	.point {
		position: absolute;
		left: 0;
		top: 50%;
		transform: translate(10%, -50%);
		aspect-ratio: 708/156;
		width: calc(0.3 * var(--content-width));
		font-size: calc(0.02 * var(--content-width));
		background-color: #ece5db;
		color: var(--text-color);
		filter: drop-shadow(0 0 calc(0.002 * var(--content-width)) rgba(179, 140, 81, 1));
	}

	.point .frame {
		height: 100%;
		width: 100%;
		display: flex;
		padding-right: 2%;
		align-items: center;
		justify-content: flex-end;
		line-height: 0;
		position: relative;
	}

	.frame::before {
		content: '';
		position: absolute;
		top: 50%;
		width: 100%;
		height: 100%;
		right: -3%;
		border-radius: 2rem;
		background-color: #ece5db;
		transform: translateY(-50%);
		z-index: -1;
	}
	.frame::after {
		content: '';
		opacity: 0.4;
		position: absolute;
		top: 50%;
		right: -1.5%;
		width: 100%;
		height: 90%;
		transform: translateY(-50%) rotate(180deg);
		background-size: contain;
		background-image: url('');
		background-repeat: no-repeat;
	}

	.number {
		margin: 0 5% 0 2%;
	}
	.number span {
		color: #f08f00;
	}
</style>
